# -*- coding: utf-8 -*-

# File Name : image_io
# Description :
# Author : marje
# date : 2022/6/5
# Change Activity : 2022/6/5

from ..misc.img_io import read_img, write_img


class ReadImage:
    def __init__(self, path_key='path', img_key='img'):
        """
        read image.

        Args:
            path_key:
            img_key:
        """
        self.path_key = path_key
        self.img_key = img_key

    @staticmethod
    def handle(path):
        """

        Args:
            path:

        Returns:
            img:BGR
        """
        return read_img(path)

    def __call__(self, data):
        path = data[self.path_key]
        res = ReadImage.handle(path)
        data[self.img_key] = res
        return data


class WriteImage:
    def __init__(self, path_key='path', img_key='img'):
        """
        read image.

        Args:
            path_key:
            img_key:
        """
        self.path_key = path_key
        self.img_key = img_key

    @staticmethod
    def handle(image, path):
        """
        write_image

        Args:
            image:
            path:

        Returns:

        """
        write_img(image, path)

    def __call__(self, data):
        path = data[self.path_key]
        img = data[self.img_key]
        WriteImage.handle(img, path)
        return data
